package cn.lysj.framework.common.validate.validate;

import cn.lysj.framework.common.validate.Message;
import cn.lysj.framework.common.validate.annotation.Pattern;
import cn.lysj.framework.common.validate.entity.Entity;

public class PatternValidate extends AbstractValidate<Pattern> {

    public boolean validate(Entity entity) {
        if (null == entity.getValue()) return false;
        java.util.regex.Pattern reg = java.util.regex.Pattern.compile(annotation.pattern());
        return reg.matcher(String.valueOf(entity.getValue())).matches();
    }

    public void init() {
        this.setMsg(annotation.message());
        this.setGroups(annotation.groups());
    }
}
